<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of interests
 *
 * @author ChristianNotebook
 */
ob_start();
session_start();

class interests extends CI_Controller
{
    function  __construct()
    {
        parent::__construct();

        if (!$this->session->userdata('is_logged_in'))
        {
            redirect('/welcome/index', 'refresh');
        }
    }

    // generates the index page where all the users interests are listed
    function index()
    {
        $data['title'] = 'Interests';
        $data['main_content'] = 'interests/user_interests';
        $data['interests'] = $this->model_interests->listInterestsByUser();
        $this->load->vars($data);
        $this->load->view('includes/template');
    }

    // generates the all_interests page where all interests are listed and it is
    function allInterests()
    {
        $data['title'] = 'See all Interests';
        $data['main_content'] = 'interests/all_interests';
        $data['results'] = $this->model_interests->listAllInterests();
        $this->load->vars($data);
        $this->load->view('includes/template');
    }

    // generates the user_interests page after a new interests has been added.
    // adds a new interest to the user by calling addNewInterestToUser in the model
    function addInterestToUser($id=0)
    {
        if ($id > 0)
        {
            $data['title'] = 'Interests';
            $data['main_content'] = 'interests/user_interests';
            $data['interests'] = $this->model_interests->listInterestsByUser();
            $this->load->vars($data);
            $this->load->view('includes/template');
            $this->model_interests->addNewInterestToUser($id);
            redirect("interests/index",'refresh');
        }
        else
        {
            $data['title'] = 'See all Interests';
            $data['main_content'] = 'interests/all_interests';
            $data['results'] = $this->model_interests->listAllInterests();
            $this->load->vars($data);
            $this->load->view('includes/template');
        }
    }

    // adds a new interest to interests by calling the model function.
    function addInterestToInterests()
    {
        $data['title'] = 'See all Interests';
        $data['main_content'] = 'interests/all_interests';
        $data['results'] = $this->model_interests->listAllInterests();
        $data['addNewInterest'] = $this->model_interests->addNewInterestToInterests();
        $this->load->vars($data);
        $this->load->view('includes/template');
        redirect('interests/allInterests','refresh');
    }

    // generates the interest_users that shows all users with a given interest
    function listUserByInterest($interest_id=0)
    {
        $data['title'] = 'Interests';
        $data['main_content'] = 'interests/interest_users';
        $data['results'] = $this->model_interests->listUsersByInterest($interest_id);
        $this->load->vars($data);
        $this->load->view('includes/template');
    }

}
?>

